﻿Imports System.Collections.Generic
Imports System.Data
Imports Sistema_InformacionNaviera.BC
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL
Imports System.Xml

Public Class BusquedaViaje
    Inherits System.Web.UI.Page
    Dim itemgridview As GridViewRow
    Dim casilla As System.Web.UI.WebControls.CheckBox

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then 
            ListarViajes()
        End If
    End Sub

    Protected Sub btnConsultar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConsultar.Click
        ListarViajes()
    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSalir.Click
        Response.Write("<script language=Javascript>window.close();</script>")
    End Sub

    Private Sub ListarViajes()

        Dim objViajeBE As New ViajesBE
        Dim objUtil As New Funciones
        If txtNave.Text.Trim <> "" Then
            objViajeBE.DesNave = objUtil.ReemplazarTexto(txtNave.Text.Trim)
        Else
            objViajeBE.DesNave = ""
        End If
       
        Dim objViaje As New ViajesBC
        dtgViaje.DataSource = objViaje.ListaViajes(objViajeBE)
        dtgViaje.DataBind()
        If dtgViaje.Rows.Count <= 0 Then
            dtgViaje.Visible = False
            lblError.Visible = True
        Else
            dtgViaje.Visible = True
            lblError.Visible = False
        End If
    End Sub


    Protected Sub btnSeleccionar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSeleccionar.Click
        Dim dt As New DataTable 
        Dim sCodVje As String = String.Empty
        Dim sDesVje As String = String.Empty
        Dim scadena As String

        For Each Me.itemgridview In dtgViaje.Rows
            casilla = itemgridview.FindControl("chkSeleccionar")

            If casilla.Checked = True Then
                sCodVje = CType(itemgridview.FindControl("lblcodigo"), Label).Text
                sDesVje = CType(itemgridview.FindControl("lblDescripcion"), Label).Text 
            End If

        Next
        scadena = sDesVje
        If sDesVje.ToString.Trim = "" Then 
            Session("BPDesViaje") = ""
            Session("BPCodViaje") = ""
            Exit Sub
        End If
        '  Response.Write("<script language=Javascript>window.returnValue = " & scadena & ";</script>")
        Response.Write("<script language=Javascript>window.close();</script>")
        Session("BPCodViaje") = sCodVje
        Session("BPDesViaje") = sDesVje

    End Sub

    Sub Cambiarpagina(ByVal sender As Object, ByVal e As GridViewPageEventArgs)

        Dim objViajeBE As New ViajesBE
        Dim objUtil As New Funciones
        If txtNave.Text.Trim <> "" Then
            objViajeBE.DesNave = objUtil.ReemplazarTexto(txtNave.Text.Trim)
        Else
            objViajeBE.DesNave = ""
        End If

        Dim objViaje As New ViajesBC
        dtgViaje.PageIndex = e.NewPageIndex
        dtgViaje.DataSource = objViaje.ListaViajes(objViajeBE)
        dtgViaje.DataBind()
        If dtgViaje.Rows.Count <= 0 Then
            dtgViaje.Visible = False
            lblError.Visible = True
        Else
            dtgViaje.Visible = True
            lblError.Visible = False
        End If

    End Sub


End Class